﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css.propertyparsers {
    import reprise.css.*;
    import reprise.utils.*;
    import reprise.css.transitions.*;

    public class DisplayPosition extends CSSPropertyParser {

        public static const POSITION_STATIC:String = "static";
        public static const OVERFLOW_HIDDEN:String = "hidden";
        public static const POSITION_ABSOLUTE:String = "absolute";
        public static const KNOWN_PROPERTIES:Object = {display:{parser:strToStringProperty, transition:VisibilityTransitionVO}, position:{parser:strToStringProperty}, overflow:{parser:parseOverflow}, overflowX:{parser:strToStringProperty}, overflowY:{parser:strToStringProperty}, left:{parser:strToIntProperty}, right:{parser:strToIntProperty}, top:{parser:strToIntProperty}, bottom:{parser:strToIntProperty}, zIndex:{parser:strToIntProperty}, width:{parser:strToIntProperty}, height:{parser:strToIntProperty}, minWidth:{parser:strToIntProperty}, maxWidth:{parser:strToIntProperty}, minHeight:{parser:strToIntProperty}, maxHeight:{parser:strToIntProperty}, boxSizing:{parser:strToStringProperty}, clear:{parser:strToStringProperty}, float:{parser:strToStringProperty}, visibility:{parser:strToStringProperty, transition:VisibilityTransitionVO}, cursor:{parser:parseCursor, inheritable:true}, tooltipDelay:{parser:strToIntProperty}, tooltipRenderer:{parser:strToStringProperty}, blendMode:{parser:strToStringProperty}, opacity:{parser:strToFloatProperty}, frameRate:{parser:strToIntProperty}, rotation:{parser:strToFloatProperty}, transform:{parser:parseTransform}, transformOrigin:{parser:parseTransformOrigin}, transformOriginX:{parser:strToIntProperty}, transformOriginY:{parser:strToIntProperty}, freezeDisplay:{parser:strToBoolProperty}};
        public static const DISPLAY_BLOCK:String = "block";
        public static const OVERFLOW_VISIBLE:String = "visible";
        public static const VISIBILITY_VISIBLE:String = "visible";
        public static const POSITION_RELATIVE:String = "relative";
        public static const CURSOR_POINTER:String = "pointer";
        public static const DISPLAY_NONE:String = "none";
        public static const VISIBILITY_HIDDEN:String = "hidden";
        public static const CURSOR_AUTO:String = "auto";
        public static const POSITION_FIXED:String = "fixed";

        public static var TRANSITION_SHORTCUTS:Object = {transformOrigin:["transformOriginX", "transformOriginY"]};

        public static function parseCursor(_arg1:String, _arg2:String):CSSProperty{
            if (_arg1.indexOf("url") != -1){
                return (strToURLProperty(_arg1, _arg2));
            };
            return (strToStringProperty(_arg1, _arg2));
        }
        public static function parseOverflow(_arg1:String, _arg2:String):CSSParsingResult{
            var _local3:Array = _arg1.split(" ");
            var _local4:CSSProperty = strToStringProperty((_local3[0] as String), _arg2);
            var _local5:CSSProperty = ((_local3.length > 1)) ? strToStringProperty((_local3[1] as String), _arg2) : strToStringProperty((_local3[0] as String), _arg2);
            return (CSSParsingResult.ResultWithPropertiesAndKeys(_local4, "overflowX", _local5, "overflowY"));
        }
        public static function parseTransform(_arg1:String, _arg2:String):CSSProperty{
            var _local8:Array;
            var _local9:Array;
            var _local10:Array;
            var _local11:String;
            var _local12:Object;
            var _local13:int;
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            _arg1 = StringUtil.trim(_local3.filteredString);
            var _local5:Array = [];
            var _local6 = "";
            var _local7:RegExp = /(\w+)\((.*?)\)/g;
            while (true) {
                _local8 = _local7.exec(_arg1);
                if (!_local8){
                    break;
                };
                _local9 = _local8[2].split(/\s*,\s*/);
                _local10 = [];
                _local11 = _local8[1];
                _local12 = {type:_local11, parameters:_local10};
                _local6 = (_local6 + (_local11 + ","));
                switch (_local11){
                    case "translate":
                        _local10[0] = strToFloatProperty(_local9[0], _arg2);
                        if (_local9.length == 1){
                            _local10[1] = _local10[0];
                        } else {
                            _local10[1] = strToFloatProperty(_local9[1], _arg2);
                        };
                        break;
                    case "scale":
                        _local10[0] = parseFloat(_local9[0]);
                        if (_local9.length == 1){
                            _local10[1] = _local10[0];
                        } else {
                            _local10[1] = parseFloat(_local9[1]);
                        };
                        break;
                    case "rotate":
                        _local10[0] = ((parseFloat(_local9[0]) * Math.PI) / 180);
                        if (_local9.length == 1){
                            _local10[1] = _local10[0];
                        } else {
                            _local10[1] = ((parseFloat(_local9[1]) * Math.PI) / 180);
                        };
                        break;
                    case "skew":
                        _local10[0] = Math.tan(((parseFloat(_local9[0]) * Math.PI) / 180));
                        if (_local9.length == 1){
                            _local10[1] = 0;
                        } else {
                            _local10[1] = Math.tan(((parseFloat(_local9[1]) * Math.PI) / 180));
                        };
                        break;
                    case "skewX":
                    case "skewY":
                        _local10[0] = Math.tan(((parseFloat(_local9[0]) * Math.PI) / 180));
                        break;
                    case "matrix":
                        _local10[0] = GeomUtil.CSSMatrixParametersToMatrix(_local9);
                        break;
                    default:
                        _local13 = _local9.length;
                        while (_local13--) {
                            _local10[_local13] = parseFloat(_local9[_local13]);
                        };
                        break;
                };
                _local5.push(_local12);
            };
            _local5.transformTypes = _local6;
            _local4.setSpecifiedValue(_local5);
            return (_local4);
        }
        public static function parseTransformOrigin(_arg1:String, _arg2:String):CSSParsingResult{
            var _local3:Array = _arg1.split(" ");
            var _local4:CSSProperty = strToIntProperty(_local3[0], _arg2);
            var _local5:CSSProperty = ((_local3.length > 1)) ? strToIntProperty(_local3[1], _arg2) : _local4;
            return (CSSParsingResult.ResultWithPropertiesAndKeys(_local4, "transformOriginX", _local5, "transformOriginY"));
        }

    }
}//package reprise.css.propertyparsers 
